package com.lyp.lease.web.admin.test;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

public class odeGenerator2 {
    public static void main(String[] args) {
        String url = "jdbc:mysql://192.168.40.100:3306/lease?useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "123456";

        String projectPath = System.getProperty("user.dir");
        // 修正路径（假设 web-admin 直接在项目根目录下）
        String mainJavaDir = projectPath + "\\web\\web-admin\\src\\main\\java";
        String resourcesDir = projectPath + "\\web\\web-admin\\src\\main\\resources";

        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("lyp")
                            .fileOverride()
                            .enableSwagger()
                            .outputDir(mainJavaDir); // 输出主目录
                })
                .packageConfig(builder -> {
                    builder
                            .parent("com.lyp.lease.web.admin")
                            .controller("controller")
                            .mapper("mapper")
                            .service("service")
                            .serviceImpl("service.impl")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, resourcesDir + "/mapper"));
                })
                .strategyConfig(builder -> {
                    builder
                            .addInclude("apartment_info") // 先指定一个“确定存在”的表测试
                            .addTablePrefix("t_", "sys_")
                            //.entityBuilder()
                            //.enableLombok()
                            //.enableTableFieldAnnotation()
                            .controllerBuilder()
                            .enableRestStyle()
                            .enableHyphenStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImpl")
                            .mapperBuilder()
                            .enableMapperAnnotation()
                            .formatMapperFileName("%sMapper")
                            .formatXmlFileName("%sMapper");
                })
                .templateConfig(builder -> {
                    builder.controller("templates/controller.java.vm");
                })
                .templateEngine(new VelocityTemplateEngine())
                .execute();

        System.out.println("代码生成完成！");
    }
}
